﻿package com.thorqq.magictimer;

import com.thorqq.magictimer.timeLoop.TimerMgr;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;

public class SplashActivity extends Activity 
{    
    private class BackgroundTask extends AsyncTask<Void, Boolean, Boolean> 
    {
        
        @Override
        protected Boolean doInBackground(Void... params) 
        {
            //计算定时器
            TimerMgr.setNextTimer(getApplicationContext(), TimerMgr.SPEC_TIME_ID_ALL);
            return true;
        }
        
        @Override
        protected void onProgressUpdate(Boolean... b )
        {
        }

        @Override
        protected void onPostExecute(Boolean result) 
        {
            Intent mainIntent = new Intent(SplashActivity.this,
                    MagicTimerActivity.class);
            SplashActivity.this.startActivity(mainIntent);
            SplashActivity.this.finish();
            overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        
        PackageManager pm = getPackageManager();
        TextView versionNumber = (TextView) findViewById(R.id.versionNumber);
        try {
               PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
               versionNumber.setText("Version " + pi.versionName);
        } 
        catch (NameNotFoundException e) 
        {
            versionNumber.setText("Unknown Version");
        }

        new BackgroundTask().execute();
    }
}